package com.sinosoft.dsp.persistence.hibernate.dao;

import java.io.Serializable;
import java.util.List;

import com.sinosoft.dsp.persistence.exception.SinoPersistenceException;

public interface CommonDao {
	/**
	 * 保存实例
	 * 
	 * @param instance
	 * @throws SinoPersistenceException
	 */
	public <T> void save(T instance) throws SinoPersistenceException;

	/**
	 * 合并实例
	 * 
	 * @param instance
	 * @return
	 * @throws SinoPersistenceException
	 */
	public <T> T merge(T instance) throws SinoPersistenceException;

	/**
	 * 删除实例
	 * 
	 * @param instance
	 * @throws SinoPersistenceException
	 */
	public <T> void delete(T instance) throws SinoPersistenceException;

	/**
	 * 通过实体类和ID，查询实体对象
	 * 
	 * @param <T>
	 * @param clazz
	 * @param id
	 * @return
	 * @throws SinoPersistenceException
	 */
	public <T> T findById(Class<T> clazz, Serializable id)
			throws SinoPersistenceException;

	/**
	 * 通过实例查询
	 * 
	 * @param instance
	 * @return
	 * @throws SinoPersistenceException
	 */
	public <T> List<T> findByExample(T instance)
			throws SinoPersistenceException;

	/**
	 * 通过一个属性查询对象列表
	 * 
	 * @param propertyName
	 * @param value
	 * @param clazz
	 * @return
	 * @throws SinoPersistenceException
	 */
	public <T> List<T> findByProperty(Class<?> clazz, String propertyName,
			Object value) throws SinoPersistenceException;

	/**
	 * 查询全部实例
	 * 
	 * @param clazz
	 * @return
	 * @throws SinoPersistenceException
	 */
	public <T> List<T> findAll(Class<?> clazz) throws SinoPersistenceException;

	/**
	 * Hql查询
	 * 
	 * @param hql
	 * @return
	 * @throws SinoPersistenceException
	 */
	public List<?> find(final String hql) throws SinoPersistenceException;

	/**
	 * Hql查询
	 * 
	 * @param hql
	 * @param values
	 * @return
	 * @throws SinoPersistenceException
	 */
	public List<?> find(final String hql, final String value)
			throws SinoPersistenceException;

	/**
	 * Hql查询
	 * 
	 * @param hql
	 * @param values
	 * @return
	 * @throws SinoPersistenceException
	 */
	public List<?> find(final String hql, final Object[] values)
			throws SinoPersistenceException;

	/**
	 * Hql唯一查询
	 * 
	 * @param hql
	 * @return
	 * @throws SinoPersistenceException
	 */
	public <T> T findUniqueResult(final String hql)
			throws SinoPersistenceException;

	/**
	 * Hql唯一查询
	 * 
	 * @param hql
	 * @param values
	 * @return
	 * @throws SinoPersistenceException
	 */
	public <T> T findUniqueResult(final String hql, final String value)
			throws SinoPersistenceException;

	/**
	 * Hql唯一查询
	 * 
	 * @param hql
	 * @param values
	 * @return
	 * @throws SinoPersistenceException
	 */
	public <T> T findUniqueResult(final String hql, final Object[] values)
			throws SinoPersistenceException;

	/**
	 * 分页查询
	 * 
	 * @param hql
	 * @param offset
	 * @param pageSize
	 * @return
	 * @throws SinoPersistenceException
	 */
	public List<?> findByPage(final String hql, final int offset,
			final int pageSize) throws SinoPersistenceException;

	/**
	 * 分页查询
	 * 
	 * @param hql
	 * @param value
	 * @param offset
	 * @param pageSize
	 * @return
	 * @throws SinoPersistenceException
	 */
	public List<?> findByPage(final String hql, final String value,
			final int offset, final int pageSize)
			throws SinoPersistenceException;

	/**
	 * 分页查询
	 * 
	 * @param hql
	 * @param values
	 * @param offset
	 * @param pageSize
	 * @return
	 * @throws SinoPersistenceException
	 */
	public List<?> findByPage(final String hql, final Object[] values,
			final int offset, final int pageSize)
			throws SinoPersistenceException;

	/**
	 * 通过Hql统计总数
	 * 
	 * @param hql
	 * @return
	 * @throws SinoPersistenceException
	 */
	public Long count(final String hql) throws SinoPersistenceException;

	/**
	 * 通过Hql统计总数
	 * 
	 * @param hql
	 * @param values
	 * @return
	 * @throws SinoPersistenceException
	 */
	public Long count(final String hql, final Object[] values)
			throws SinoPersistenceException;

}
